<?php
	/**
	*Author 雷日锦 362606856@qq.com 
	*控制器自动生成
	*/
	if(!defined("ROOT_PATH")) exit("die Access ");
	class cyitem_askControl extends skymvc{
		
		public function __construct(){
			parent::__construct();
		}
		
		public function onDefault(){
			$cyid=get_post('cyid','i');
			$cyitem=M("cyitem")->selectRow("id=".$cyid);
 			if(empty($cyitem)) $this->goAll("数据出错",1,0,"/index.php");
			$where=" cyid=".$cyid;
			$url="/index.php?m=cyitem_ask&a=default";
			$limit=20;
			$start=get("per_page","i");
			$option=array(
				"start"=>intval(get_post('per_page')),
				"limit"=>$limit,
				"order"=>" id DESC",
				"where"=>$where
			);
			$rscount=true;
			$data=M("cyitem_ask")->select($option,$rscount);
			$pagelist=$this->pagelist($rscount,$limit,$url);
			$this->smarty->assign(
				array(
					"data"=>$data,
					"pagelist"=>$pagelist,
					"rscount"=>$rscount,
					"url"=>$url
				)
			);
			$tpl=M("pagetpl")->get("cyitem_ask","index");
			$this->smarty->display($tpl);
			 
		}
		
		
		public function onList(){
			$where="";
			$url="/index.php?m=cyitem_ask&a=default";
			$limit=20;
			$start=get("per_page","i");
			$option=array(
				"start"=>intval(get_post('per_page')),
				"limit"=>$limit,
				"order"=>" id DESC",
				"where"=>$where
			);
			$rscount=true;
			$data=M("cyitem_ask")->select($option,$rscount);
			$pagelist=$this->pagelist($rscount,$limit,$url);
			$this->smarty->assign(
				array(
					"data"=>$data,
					"pagelist"=>$pagelist,
					"rscount"=>$rscount,
					"url"=>$url
				)
			);
			$tpl=M("pagetpl")->get("cyitem_ask","list");
			$this->smarty->display($tpl);
		 
		}
		
		public function onShow(){
			$id=get_post("id","i");
			if($id){
				$data=M("cyitem_ask")->selectRow(array("where"=>"id={$id}"));
				
			}
			$this->smarty->assign(array(
				"data"=>$data
			));
			$this->smarty->display("cyitem_ask/show.html");
			$tpl=M("pagetpl")->get("cyitem_ask","show");
			$this->smarty->display($tpl);
		}
		public function onAdd(){
			$id=get_post("id","i");
			if($id){
				$data=M("cyitem_ask")->selectRow(array("where"=>"id={$id}"));
				
			}
			$this->smarty->assign(array(
				"data"=>$data
			));
			$tpl=M("pagetpl")->get("cyitem_ask","add");
			$this->smarty->display($tpl);
			$this->smarty->display("cyitem_ask/add.html");
		}
		
		public function onSave(){
			
			$id=get_post("id","i");
			$data["title"]=post("title","h");
			$data["cyitem_id"]=post("cyitem_id","i");
			$data["pid"]=post("pid","i");
			$data["content"]=post("content","h");
			$data["reply_content"]=post("reply_content","h");
			$data["userid"]=M("login")->userid;
			$data["dateline"]=time();
			$data["status"]=0;

			if($id){
				M("cyitem_ask")->update($data,"id='$id'");
			}else{
				M("cyitem_ask")->insert($data);
			}
			$this->goall("保存成功");
		}
		
		public function onStatus(){
			$id=get_post('id',"i");
			$status=get_post("status","i");
			M("cyitem_ask")->update(array("status"=>$status),"id=$id");
			$this->sexit(json_encode(array("error"=>0,"message"=>"状态修改成功")));
		}
		
		public function onDelete(){
			$id=get_post('id',"i");
			M("cyitem_ask")->delete("id=".$id);
			$this->sexit(json_encode(array("error"=>0,"message"=>"删除成功")));
		}
		
		
	}

?>